import {defineStore} from "pinia";
// export const useMoneyStore = defineStore('money', {
//     state: () => ({money: 100}),
//     getters: {
//         rmb: (state) => state.money,
//         usd: (state) => state.money * 0.14,
//         eur: (state) => state.money * 0.13,
//     },
//     actions: {
//         win(arg) {
//             this.money+=arg;
//         },
//         pay(arg){
//             this.money -= arg;
//         }
//     },
// });

export const useMoneyStore = defineStore('money', () => {
    const salary = ref(1000); // ref() 就是 state 属性
    const dollar = computed(() => salary.value * 0.14); //  computed() 就是 getters
    const eur = computed(() => salary.value * 0.13); // computed() 就是 getters

    //function() 就是 actions
    const pay = () => {
        salary.value -= 100;
    }

    const win = () => {
        salary.value += 1000;
    }

    //重要：返回可用对象
    return {salary,dollar,eur,pay,win}
})